package com.itboye.jigongbao.web

import android.annotation.SuppressLint
import android.view.View
import android.webkit.*
import android.widget.RelativeLayout
import com.itboye.jigongbao.R
import com.itboye.jigongbao.base.BaseActivity
import com.itboye.jigongbao.utils.TitleBarUtils
import kotlinx.android.synthetic.main.activity_web.*

class WebActivity : BaseActivity() {

    var lay_actionbar_left: RelativeLayout? = null
    override fun onClick(v: View?) {
        when (v) {
            lay_actionbar_left -> {
                finish()
            }
            else -> {
            }
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_web
    }

    var webSettings: WebSettings? = null
    @SuppressLint("JavascriptInterface")
    override fun initData() {
        TitleBarUtils().initTitlebarStyle1(this, action_bar_web, intent.getStringExtra("title"), R.drawable.img_back, "", 0, "")
        webView.loadUrl(intent.getStringExtra("url"))
        webSettings = webView.settings
        //设置支持JavaScript
        webSettings?.loadWithOverviewMode = true
        webSettings?.javaScriptEnabled = true
        //设置不调用浏览器，使用本WebView
        webView.setWebViewClient(object : WebViewClient() {
            override fun onPageFinished(view: WebView?, url: String?) {
                super.onPageFinished(view, url)
            }

            override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
//                MAlert.alert("当前无网络连接")
                super.onReceivedError(view, request, error)
            }
        })
    }
}
